package com.six.usersso.service.impl;

import com.six.core.entity.TbUser;
import com.six.usersso.feign.TbUserFeign;
import com.six.usersso.service.TbUserService;
import com.six.usersso.vo.MyUser;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.userdetails.User;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.stereotype.Service;
import org.springframework.util.AutoPopulatingList;

import java.util.ArrayList;
import java.util.Collection;

/**
 * @author: WangPeng
 * @createTime: 2023/03/01 16:39
 * @description:
 * @version: v1.0
 */
@Service
public class TbUserServiceImpl implements TbUserService {
    @Autowired
    private TbUserFeign tbUserFeign;
    @Override
    public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {
        System.out.println("==============="+username);
        TbUser tbUser = tbUserFeign.getByMobile(username);
        if (tbUser!=null){
            return new MyUser(username,tbUser.getPassword(),new ArrayList<>(),tbUser);
        }
        return null;
    }
}
